package com.mhy.dump;

import android.os.Build;
import android.util.Log;

import com.swift.sandhook.xposedcompat.BuildConfig;

import java.io.File;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.callbacks.XC_LoadPackage;


/**
 * Created By Mahongyin
 * Date    2021/2/28 14:34
 */
public class HookXposed implements IXposedHookLoadPackage {

    public static void log(String txt) {

        Log.i("hook","dumpdex-> " + txt);
    }

    public static void log(Throwable t) {
        if (!BuildConfig.DEBUG) {
            return;
        }
        Log.i("hook",t.getMessage());
    }

    @Override
    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) {

        final String packageName = lpparam.packageName;
        if (lpparam.packageName.equals(packageName)) {
            String path = "/data/data/" + packageName + "/dump";
            File parent = new File(path);
            if (!parent.exists() || !parent.isDirectory()) {
                parent.mkdirs();
            }
            log("sdk version:" + Build.VERSION.SDK_INT);
            if (DeviceUtils.isOreo() || DeviceUtils.isPie() || DeviceUtils.isAndroid10()) {
                OreoDump.init(lpparam);
            } else {
                LowSdkDump.init(lpparam);
            }

        }
    }
}
